﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Data.Entity;
using DAO;

namespace BUS
{
    public class BUS_WRENTSALETYPE
    {
        WRMOEntities db = new WRMOEntities();

        public IList<WRENTSALETYPE> _GetList()
        {
            return db.WRENTSALETYPEs.ToList();
        }

        public IList<WRENTSALETYPE> _GetList(Func<WRENTSALETYPE, bool> cond)
        {
            return db.WRENTSALETYPEs.Where(cond).ToList();
        }

        public WRENTSALETYPE _GetObject(int ID)
        {
            return db.WRENTSALETYPEs.Where(p => p.ID == ID).FirstOrDefault();
        }

        public WRENTSALETYPE _GetObject(Func<WRENTSALETYPE, bool> cond)
        {
            return db.WRENTSALETYPEs.Where(cond).FirstOrDefault();
        }

        public WRENTSALETYPE _CreateObject()
        {
            return db.WRENTSALETYPEs.CreateObject();
        }

        public void _Save()
        {
            db.SaveChanges();
        }

        public void _Add(WRENTSALETYPE entity, bool save = true)
        {
            try
            {
                db.AddToWRENTSALETYPEs(entity);
                if (save)
                    _Save();
            }
            catch (Exception ex)
            {

                throw ex;
            }
        }

        public void _Update(WRENTSALETYPE entity)
        {
            try
            {
                WRENTSALETYPE _mainEntity = db.WRENTSALETYPEs.Where(p => p.ID == entity.ID).FirstOrDefault();
                if (_mainEntity != null)
                {
                    _mainEntity = entity;
                }
                _Save();
            }
            catch (Exception ex)
            {

                throw ex;
            }
        }

        public void _Delete(int ID)
        {
            try
            {
                WRENTSALETYPE _mainEntity = db.WRENTSALETYPEs.Where(p => p.ID == ID).FirstOrDefault();
                if (_mainEntity != null)
                {
                    db.WRENTSALETYPEs.DeleteObject(_mainEntity);
                }
            }
            catch (Exception ex)
            {

                throw ex;
            }
        }

        public void _Delete(WRENTSALETYPE entity)
        {
            try
            {
                WRENTSALETYPE _mainEntity = db.WRENTSALETYPEs.Where(p => p.ID == entity.ID).FirstOrDefault();
                if (_mainEntity != null)
                {
                    db.WRENTSALETYPEs.DeleteObject(_mainEntity);
                }
            }
            catch (Exception ex)
            {

                throw ex;
            }
        }
    }
}
